package cn.tonyandmoney.voicenotes.notes.entity;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Unique;

import java.io.File;

import cn.tonyandmoney.voicenotes.wav.WavConstants;

/**
 * 语音笔记的原始文件以所属的笔记名称为准
 * content  当做是文件的描述吧，这个讲
 */
@Entity
public class TRecord implements Cloneable {
    @Id(autoincrement = true)
    @Unique
    private Long id;
    private String content;
    private String path;
    private Long duration;
    private float volume = 1f;
    private int channel = WavConstants.channels;
    private int sampleRate = WavConstants.sampleRate;
    private int bitNum = WavConstants.bitNum;

    @Generated(hash = 1679142879)
    public TRecord(Long id, String content, String path, Long duration,
                   float volume, int channel, int sampleRate, int bitNum) {
        this.id = id;
        this.content = content;
        this.path = path;
        this.duration = duration;
        this.volume = volume;
        this.channel = channel;
        this.sampleRate = sampleRate;
        this.bitNum = bitNum;
    }

    @Generated(hash = 524517064)
    public TRecord() {
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getContent() {
        return this.content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getPath() {
        return this.path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public Long getDuration() {
        return this.duration;
    }

    public void setDuration(Long duration) {
        this.duration = duration;
    }

    public float getVolume() {
        return this.volume;
    }

    public void setVolume(float volume) {
        this.volume = volume;
    }

    public int getChannel() {
        return this.channel;
    }

    public void setChannel(int channel) {
        this.channel = channel;
    }

    public int getSampleRate() {
        return this.sampleRate;
    }

    public void setSampleRate(int sampleRate) {
        this.sampleRate = sampleRate;
    }

    public int getBitNum() {
        return this.bitNum;
    }

    public void setBitNum(int bitNum) {
        this.bitNum = bitNum;
    }


    public String getFileName() {
        File file = new File(path);
        if (file.exists()) {
            return file.getName();
        }
        return "无";
    }

    @Override
    public TRecord clone() {
        try {
            return (TRecord) super.clone();
        } catch (CloneNotSupportedException e) {
            TRecord tRecord = new TRecord();
            tRecord.setContent(content);
            tRecord.setVolume(volume);
            return tRecord;
        }

    }
}
